/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @param {number} val
 * @return {ListNode}
 */
var removeElements = function(head, val) {
    if(head===null)return null
    while(head!==null&&head.val===val)
    {
        head=head.next
    }
    if(head===null)return null
        let curr=head
        let curr1=head.next
        while(curr.next!==null){
            if(curr1.val===val ){
                curr.next=curr1.next
                curr1=curr1.next
            }
            else{
                curr=curr.next
                curr1=curr1.next
            }
        }
        return head


    
};